package com.example.zidinyi;



import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.recyclerview.MainActivity;
import com.example.recyclerview.R;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

public class RecyclerViewAdapterMiddle extends RecyclerView.Adapter<RecyclerViewAdapterMiddle.MyViewHolder> {

    private Context mContext;
    private List<MusicInfoData> list;
    RecyclerCoverFlow recyclerCoverFlow;
    private String TAG = "RecyclerViewAdapter";

    public RecyclerViewAdapterMiddle(Context mContext, List<MusicInfoData> list, RecyclerCoverFlow recyclerCoverFlow) {
        this.mContext = mContext;
        this.list = list;
        this.recyclerCoverFlow = recyclerCoverFlow;

    }

    public void SetDataSource(List<MusicInfoData> mlist) {
        list = mlist;
        this.notifyDataSetChanged();
    }

    public List<MusicInfoData> getDataSource() {
        return list;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView item_text;
        ImageView item_image;
        // RecyclerCoverFlow coverFlow;

        public MyViewHolder(View itemView) {
            super(itemView);
            item_image = itemView.findViewById(R.id.img);
            item_text = itemView.findViewById(R.id.tv);
            // coverFlow = itemView.findViewById(R.id.recyclerCoverFlow);
        }
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.recyclerview_item, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.item_text.setText(list.get(position).getName());

        checkBitmap(holder, position);

       /* holder.item_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                recyclerCoverFlow.getCoverFlowLayout().smoothScrollToPosition(recyclerCoverFlow, new RecyclerView.State(), position);
                ((MainActivity) mContext).setFirst_scroll(false);
            }
        });*/
    }

    private void checkBitmap(MyViewHolder holder, int position) {
        byte[] b = list.get(position).getBytes();
        /*if (b != null) {
            Glide.with(mContext).load(b).into(holder.item_image);
        } else{
            Glide.with(mContext).load(R.drawable.cdh).into(holder.item_image);

        }*/

     //     holder.item_image.setImageResource(R.drawable.cdh);
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }


}

